package cn.zjweu.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class BeanCopyUtils {

    private BeanCopyUtils() {}


    public static <T> T copyBean(Object source, Class<T> clazz) {

        T target = null;
        try {
            target = clazz.newInstance();
            BeanUtils.copyProperties(source, target);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return target;
    }
    public static <O,T> List<T> copyBeanList(List<O> sourceList, Class<T> clazz) {

        List<T> targetList = new ArrayList<>();
        try {
            for (Object obj : sourceList) {
                T target = null;
                target = copyBean(obj, clazz);
                targetList.add(target);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return targetList;
    }

    public static void main(String[] args) {

    }

}
